package com.dev.utils.app;


import java.lang.reflect.Field;

import com.dev.DevUtils;
import com.dev.utils.LogPrintUtils;

import com.dev.utils.LogUtils;
import com.dev.utils.common.FieldUtils;
import ohos.aafwk.ability.Ability;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.PixelMapElement;
import ohos.agp.components.element.ShapeElement;
import ohos.app.AbilityContext;
import ohos.app.Context;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;

/**
 * detail: Component 操作相关工具类
 *
 * @author Ttt
 * <pre>
 *     组件设置 setCompoundDrawables 不生效解决办法
 *     @see <a href="https://blog.csdn.net/qq_26971803/article/details/54347598"/>
 *      常用布局属性
 *     @see <a href="https://www.jianshu.com/p/78e2dfb6d244"/>
 *      应用坐标系统全面详解
 *     @see <a href="https://blog.csdn.net/yanbober/article/details/50419117"/>
 *     <p></p>
 *     RelativeLayout 的特有属性
 *     属性值为 true、false
 *     layout_centerHrizontal 位于父控件的横向中间位置
 *     layout_centerVertical 位于父控件的纵向中间位置
 *     layout_centerInparent 位于父控件的纵横向中间位置
 *     layout_alignParentBottom 贴紧父元素的下边缘
 *     layout_alignParentLeft 贴紧父元素的左边缘
 *     layout_alignParentRight 贴紧父元素的右边缘
 *     layout_alignParentTop 贴紧父元素的上边缘
 *     layout_alignParentStart 将控件开始位置与父控件的开始位置对齐
 *     layout_alignParentEnd 将控件结束位置与父控件的结束位置对齐
 *     属性值为引用 id
 *     layout_below 在某元素的下方
 *     layout_above 在某元素的的上方
 *     layout_toLeftOf 在某元素的左边
 *     layout_toRightOf 在某元素的右边
 *     layout_toStartOf 在某元素的开始位置
 *     layout_toEndOf 在某元素的结束位置
 *     layout_alignTop 本元素的上边缘和某元素的的上边缘对齐
 *     layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐
 *     layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐
 *     layout_alignRight 本元素的右边缘和某元素的的右边缘对齐
 *     layout_alignStart 本元素与某元素开始位置对齐
 *     layout_alignEnd 本元素与某元素结束位置对齐
 *     layout_alignBaseline 将当前控件的基线与指定 id 控件 t 的基线对齐
 * </pre>
 */
public final class ViewUtils {

    private ViewUtils() {
    }

    // 日志 TAG
    private static final String TAG = ViewUtils.class.getSimpleName();
    // MATCH_PARENT
    public static final int MATCH_PARENT = ComponentContainer.LayoutConfig.MATCH_PARENT;
    // WRAP_CONTENT
    public static final int WRAP_CONTENT = ComponentContainer.LayoutConfig.MATCH_CONTENT;

    /**
     * 获取 Context
     *
     * @param view {@link Context}
     * @return {@link Context}
     */
    public static Context getContext(final Component view) {
        if (view != null) {
            return view.getContext();
        }
        return null;
    }

    /**
     * 获取 Component context 所属的 Activity
     *
     * @param view {@link Component}
     * @return {@link Ability}
     */
    public static Ability getActivity(final Component view) {
        if (view != null) {
            try {
                Context context = view.getContext();
                while (context instanceof AbilityContext) {
                    if (context instanceof Ability) {
                        return (Ability) context;
                    }
                    context = context.getApplicationContext();
                }
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "getActivity");
            }
        }
        return null;
    }

    // =

    /**
     * 获取 Component
     *
     * @param resource R.layout.id
     * @return {@link Component}
     */
    public static Component inflate(final int resource) {
        return inflate(resource, null, false);
    }

    /**
     * 获取 Component
     *
     * @param resource R.layout.id
     * @param root     {@link ComponentContainer}
     * @return {@link Component}
     */
    public static Component inflate(
            final int resource,
            final ComponentContainer root
    ) {
        return inflate(resource, root, root != null);
    }
    /**
     * 获取 Component
     *
     * @param resource     R.layout.id
     * @param root         {@link ComponentContainer}
     * @param attachToRoot 是否添加到 root 上
     * @return {@link Component}
     */
    public static Component inflate(
            final int resource,
            final ComponentContainer root,
            final boolean attachToRoot
    ) {
        try {
            return LayoutScatter.getInstance(DevUtils.getContext()).parse(resource, root, attachToRoot);
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "inflate");
        }
        return null;
    }

    /**
     * 获取 Component
     *
     * @param context  {@link Context}
     * @param resource R.layout.id
     * @return {@link Component}
     */
    public static Component inflate(
            final Context context,
            final int resource
    ) {
        return inflate(context, resource, null, false);
    }

    /**
     * 获取 Component
     *
     * @param context  {@link Context}
     * @param resource R.layout.id
     * @param root     {@link ComponentContainer}
     * @return {@link Component}
     */
    public static Component inflate(
            final Context context,
            final int resource,
            final ComponentContainer root
    ) {
        return inflate(context, resource, root, root != null);
    }

    /**
     * 获取 Component
     * <pre>
     *
     * </pre>
     *
     * @param context      {@link Context}
     * @param resource     R.layout.id
     * @param root         {@link ComponentContainer}
     * @param attachToRoot 是否添加到 root 上
     * @return {@link Component}
     */
    public static Component inflate(
            final Context context,
            final int resource,
            final ComponentContainer root,
            final boolean attachToRoot
    ) {
        try {
            return LayoutScatter.getInstance(context).parse(resource, root, attachToRoot);
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "inflate");
        }
        return null;
    }

    // =

    /**
     * 获取 Component Id
     *
     * @param view {@link Component}
     * @return Component Id
     */
    public static int getId(final Component view) {
        if (view != null) return view.getId();
        return Component.ID_DEFAULT;
    }

    /**
     * 设置 Component Id
     *
     * @param view {@link Component}
     * @param id   Component Id
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setId(
            final Component view,
            final int id
    ) {
        if (view != null) {
            view.setId(id);
            return true;
        }
        return false;
    }

    /**
     * 获取指定 Component 父布局
     *
     * @param view {@link Component}
     * @param <T>  泛型
     * @return {@link Component}
     */
    public static <T extends Component> T getParent(final Component view) {
        if (view != null) {
            try {
                return (T) view.getComponentParent();
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "getParent");
            }
        }
        return null;
    }

//    /**
//     *
//     * @param activity {@link Ability}
//     * @param <T>      泛型
//     * @return {@link Component}
//     */
//    public static <T extends Component> T getContentComponent(final Ability activity) {
//        return ComponentUtils.findComponentById(activity, ResourceTable.Layout);
//    }

//    /**
//     *
//     * @param view {@link Component}
//     * @param <T>  泛型
//     * @return {@link Component}
//     */
//    public static <T extends Component> T getContentComponent(final Component view) {
//        if (view != null) {
//            try {
//                ComponentParent parent = view.getParent();
//                while (parent instanceof Component) {
//                    Component root = (Component) parent;
//                    if (root.getId() == R.id.content) {
//                        return (T) root;
//                    }
//                    parent = parent.getParent();
//                }
//            } catch (Exception e) {
//                LogPrintUtils.eTag(TAG, e, "getContentComponent");
//            }
//        }
//        return null;
//    }

    /**
     * 获取指定 Component 根布局 ( 最底层布局 )
     *
     * @param view {@link Component}
     * @param <T>  泛型
     * @return {@link Component}
     */
    public static <T extends Component> T getRootParent(final Component view) {
        if (view != null) {
            try {
                Component root = null;
                ComponentParent parent = view.getComponentParent();
                while (parent instanceof Component) {
                    root = (Component) parent;
                    parent = parent.getComponentParent();
                }
                return (T) root;
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "getRootParent");
            }
        }
        return null;
    }


//    /**
//     * 设置是否限制子 Component 在其边界内绘制
//     * @param viewGroup    {@link ComponentGroup}
//     * @param clipChildren {@code true} yes, {@code false} no
//     * @return {@code true} success, {@code false} fail
//     */
//    public static boolean setClipChildren(
//            final ComponentContainer viewGroup,
//            final boolean clipChildren
//    ) {
//        if (viewGroup != null) {
//            viewGroup.chi(clipChildren);
//            return true;
//        }
//        return false;
//    }

    // =

    /**
     * 获取子 Component 总数
     *
     * @param viewGroup {@link Component}
     * @return 子 Component 总数
     */
    public static int getChildCount(final ComponentContainer viewGroup) {
        if (viewGroup != null) {
            return viewGroup.getChildCount();
        }
        return 0;
    }

    /**
     * 获取指定索引 Component
     *
     * @param viewGroup {@link Component}
     * @param <T>       泛型
     * @return {@link Component}
     */
    public static <T extends Component> T getChildAt(final ComponentContainer viewGroup) {
        return getChildAt(viewGroup, 0);
    }

    /**
     * 获取最后一个索引 Component
     *
     * @param viewGroup {@link ComponentContainer}
     * @param <T>       泛型
     * @return {@link Component}
     */
    public static <T extends Component> T getChildAtLast(final ComponentContainer viewGroup) {
        if (viewGroup == null) return null;
        return getChildAt(viewGroup, viewGroup.getChildCount() - 1);
    }

    /**
     * 获取指定索引 Component
     *
     * @param viewGroup {@link ComponentContainer}
     * @param index     索引
     * @param <T>       泛型
     * @return {@link Component}
     */
    public static <T extends Component> T getChildAt(
            final ComponentContainer viewGroup,
            final int index
    ) {
        if (viewGroup != null && index >= 0) {
            try {
                return (T) viewGroup.getComponentAt(index);
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "getChildAt");
            }
        }
        return null;
    }

    /**
     * 移除全部子 Component
     *
     * @param viewGroup {@link ComponentContainer}
     * @param <T>       泛型
     * @return 传入 Component
     */
    public static <T extends ComponentContainer> T removeAllComponents(final T viewGroup) {
        if (viewGroup != null) {
            viewGroup.removeAllComponents();
        }
        return viewGroup;
    }

    /**
     * 获取全部子 Component
     *
     * @param viewGroup {@link ComponentContainer}
     * @return Component[]
     */
    public static Component[] getChilds(final ComponentContainer viewGroup) {
        Component[] views = new Component[getChildCount(viewGroup)];
        for (int i = 0, len = views.length; i < len; i++) {
            views[i] = getChildAt(viewGroup, i);
        }
        return views;
    }

    // =

    /**
     * 获取 LayoutParams
     *
     * @param view {@link Component}
     * @param <T>  泛型
     * @return LayoutParams
     */
    public static <T> T getLayoutParams(final Component view) {
        if (view != null) {
            try {
                return (T) view.getLayoutConfig();
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "getLayoutParams");
            }
        }
        return null;
    }

    /**
     * 设置 Component LayoutParams
     *
     * @param view   {@link Component}
     * @param params LayoutParams
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setLayoutParams(
            final Component view,
            final ComponentContainer.LayoutConfig params
    ) {
        if (view != null) {
            try {
                view.setLayoutConfig(params);
                return true;
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "setLayoutParams");
            }
        }
        return false;
    }

    // =====================
    // = 初始化 Component 操作等 =
    // =====================

    /**
     * 初始化 Component
     *
     * @param view {@link Component}
     * @param id   R.id.viewId
     * @param <T>  泛型
     * @return {@link Component}
     */
    public static <T extends Component> T findComponentById(
            final Component view,
            final int id
    ) {
        if (view != null) {
            try {
                return (T) view.findComponentById(id);
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "findComponentById");
            }
        }
        return null;
    }

//    /**
//     * 初始化 Component
//     * @param window {@link Window}
//     * @param id     R.id.viewId
//     * @param <T>    泛型
//     * @return {@link Component}
//     */
//    public static <T extends Component> T findComponentById(
//            final Window window,
//             final int id
//    ) {
//        if (window != null) {
//            try {
//                return window.findComponentById(id);
//            } catch (Exception e) {
//                LogPrintUtils.eTag(TAG, e, "findComponentById");
//            }
//        }
//        return null;
//    }

    /**
     * 初始化 Component
     *
     * @param activity {@link Ability}
     * @param id       R.id.viewId
     * @param <T>      泛型
     * @return {@link Component}
     */
    public static <T extends Component> T findComponentById(
            final Ability activity,
            final int id
    ) {
        if (activity != null) {
            try {
                return (T) activity.findComponentById(id);
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "findComponentById");
            }
        }
        return null;
    }

    /**
     * 转换 Component
     *
     * @param view {@link Component}
     * @param <T>  泛型
     * @return {@link Component}
     */
    public static <T extends Component> T convertComponent(final Component view) {
        try {
            return (T) view;
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "convertComponent");
        }
        return null;
    }

    // =============
    // = Component 判空 =
    // =============

    /**
     * 判断 Component 是否为 null
     *
     * @param view {@link Component}
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isEmpty(final Component view) {
        return view == null;
    }

    /**
     * 判断 Component 是否为 null
     *
     * @param views Component[]
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isEmpty(final Component... views) {
        if (views != null && views.length != 0) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view == null) {
                    return true;
                }
            }
            return false;
        }
        return true;
    }

    /**
     * 判断 Component 是否不为 null
     *
     * @param view {@link Component}
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isNotEmpty(final Component view) {
        return view != null;
    }

    /**
     * 判断 Component 是否不为 null
     *
     * @param views Component[]
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isNotEmpty(final Component... views) {
        if (views != null && views.length != 0) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view == null) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    // =

    /**
     * 获取 Component 宽高
     *
     * @param view {@link Component}
     * @return int[], 0 = 宽度, 1 = 高度
     */
    public static int[] getWidthHeight(final Component view) {
        if (view != null) {
            return new int[]{view.getWidth(), view.getHeight()};
        }
        return new int[]{0, 0};
    }

    /**
     * 设置 Component 宽度、高度
     *
     * @param view   {@link Component}
     * @param width  Component 宽度
     * @param height Component 高度
     * @return {@link Component}
     */
    public static Component setWidthHeight(
            final Component view,
            final int width,
            final int height
    ) {
        return setWidthHeight(view, width, height, true);
    }

    /**
     * 设置 Component 宽度、高度
     *
     * @param view      {@link Component}
     * @param width     Component 宽度
     * @param height    Component 高度
     * @param nullNewLP 如果 LayoutParams 为 null 是否创建新的
     * @return {@link Component}
     */
    public static Component setWidthHeight(
            final Component view,
            final int width,
            final int height,
            final boolean nullNewLP
    ) {
        if (view != null) {
            try {
                ComponentContainer.LayoutConfig layoutParams = view.getLayoutConfig();
                if (layoutParams != null) {
                    layoutParams.width = width;
                    layoutParams.height = height;
                    view.setLayoutConfig(layoutParams);
                } else if (nullNewLP) {
                    layoutParams = new ComponentContainer.LayoutConfig(width, height);
                    view.setLayoutConfig(layoutParams);
                }
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "setWidthHeight");
            }
        }
        return view;
    }

    // =

    /**
     * 获取 Component 宽度
     *
     * @param view {@link Component}
     * @return Component 宽度
     */
    public static int getWidth(final Component view) {
        if (view != null) {
            return view.getWidth();
        }
        return 0;
    }

    /**
     * 设置 Component 宽度
     *
     * @param view  {@link Component}
     * @param width Component 宽度
     * @return {@link Component}
     */
    public static Component setWidth(
            final Component view,
            final int width
    ) {
        return setWidth(view, width, true);
    }

    /**
     * 设置 Component 宽度
     *
     * @param view      {@link Component}
     * @param width     Component 宽度
     * @param nullNewLP 如果 LayoutParams 为 null 是否创建新的
     * @return {@link Component}
     */
    public static Component setWidth(
            final Component view,
            final int width,
            final boolean nullNewLP
    ) {
        if (view != null) {
            try {
                ComponentContainer.LayoutConfig layoutParams = view.getLayoutConfig();
                if (layoutParams != null) {
                    layoutParams.width = width;
                    view.setLayoutConfig(layoutParams);
                } else if (nullNewLP) {
                    layoutParams = new ComponentContainer.LayoutConfig(width, ComponentContainer.LayoutConfig.MATCH_PARENT);
                    view.setLayoutConfig(layoutParams);
                }
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "setWidth");
            }
        }
        return view;
    }

    // =

    /**
     * 获取 Component 高度
     *
     * @param view {@link Component}
     * @return Component 高度
     */
    public static int getHeight(final Component view) {
        if (view != null) {
            return view.getHeight();
        }
        return 0;
    }

    /**
     * 设置 Component 高度
     *
     * @param view   {@link Component}
     * @param height Component 高度
     * @return {@link Component}
     */
    public static Component setHeight(
            final Component view,
            final int height
    ) {
        return setHeight(view, height, true);
    }

    /**
     * 设置 Component 高度
     *
     * @param view      {@link Component}
     * @param height    Component 高度
     * @param nullNewLP 如果 LayoutParams 为 null 是否创建新的
     * @return {@link Component}
     */
    public static Component setHeight(
            final Component view,
            final int height,
            final boolean nullNewLP
    ) {
        if (view != null) {
            try {
                ComponentContainer.LayoutConfig layoutParams = view.getLayoutConfig();
                if (layoutParams != null) {
                    layoutParams.height = height;
                    view.setLayoutConfig(layoutParams);
                } else if (nullNewLP) {
                    layoutParams = new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, height);
                    view.setLayoutConfig(layoutParams);
                }
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "setHeight");
            }
        }
        return view;
    }

    // =

    /**
     * 获取 Component 最小高度
     *
     * @param view Component
     * @return Component 最小高度
     */
    public static int getMinimumHeight(final Component view) {
        if (view != null) {
            return view.getMinHeight();
        }
        return 0;
    }

    /**
     * 设置 Component 最小高度
     *
     * @param view      {@link Component}
     * @param minHeight 最小高度
     * @return {@link Component}
     */
    public static Component setMinimumHeight(
            final Component view,
            final int minHeight
    ) {
        if (view != null) {
            view.setMinHeight(minHeight);
        }
        return view;
    }

    /**
     * 获取 Component 最小宽度
     *
     * @param view Component
     * @return Component 最小宽度
     */
    public static int getMinimumWidth(final Component view) {
        if (view != null) {
            return view.getMinWidth();
        }
        return 0;
    }

    /**
     * 设置 Component 最小宽度
     *
     * @param view     {@link Component}
     * @param minWidth 最小宽度
     * @return {@link Component}
     */
    public static Component setMinimumWidth(
            final Component view,
            final int minWidth
    ) {
        if (view != null) {
            view.setMinWidth(minWidth);
        }
        return view;
    }

    // =

    /**
     * 获取 Component 透明度
     *
     * @param view Component
     * @return 透明度
     */
    public static float getAlpha(final Component view) {
        if (view != null) {
            return view.getAlpha();
        }
        return 1.0f;
    }

    /**
     * 设置 Component 透明度
     *
     * @param view  Component
     * @param alpha 透明度
     * @return {@link Component}
     */
    public static Component setAlpha(
            final Component view,
            final float alpha
    ) {
        if (view != null) {
            view.setAlpha(alpha);
        }
        return view;
    }

    /**
     * 获取 Component Tag
     *
     * @param view Component
     * @return Tag
     */
    public static Object getTag(final Component view) {
        if (view != null) {
            return view.getTag();
        }
        return null;
    }

    /**
     * 设置 Component Tag
     *
     * @param view   Component
     * @param object Tag
     * @return {@link Component}
     */
    public static Component setTag(
            final Component view,
            final Object object
    ) {
        if (view != null) {
            view.setTag(object);
        }
        return view;
    }

    // =

    /**
     * Component 内容滚动位置 ( 相对于初始位置移动 )
     * <pre>
     *     无滚动过程
     * </pre>
     *
     * @param view {@link Component}
     * @param x    X 轴开始坐标
     * @param y    Y 轴开始坐标
     * @return {@link Component}
     */
    public static Component scrollTo(
            final Component view,
            final int x,
            final int y
    ) {
        if (view != null) view.scrollTo(x, y);
        return view;
    }

    /**
     * Component 内部滚动位置 ( 相对于上次移动的最后位置移动 )
     * <pre>
     *     无滚动过程
     * </pre>
     *
     * @param view {@link Component}
     * @param x    X 轴开始坐标
     * @param y    Y 轴开始坐标
     * @return {@link Component}
     */
    public static Component scrollBy(
            final Component view,
            final int x,
            final int y
    ) {
        if (view != null) view.scrollBy(x, y);
        return view;
    }

    /**
     * 设置 Component 滑动的 X 轴坐标
     *
     * @param view  {@link Component}
     * @param value X 轴坐标
     * @return {@link Component}
     */
    public static Component setScrollX(
            final Component view,
            final int value
    ) {
        if (view != null) view.setScrollbarStartAngle(value);
        return view;
    }

    /**
     * 设置 Component 滑动的 Y 轴坐标
     *
     * @param view  {@link Component}
     * @param value Y 轴坐标
     * @return {@link Component}
     */
    public static Component setScrollY(
            final Component view,
            final int value
    ) {
        if (view != null) view.setScaleY(value);
        return view;
    }

    /**
     * 获取 Component 滑动的 X 轴坐标
     *
     * @param view {@link Component}
     * @return 滑动的 X 轴坐标
     */
    public static int getScrollX(final Component view) {
        return view != null ? (int) view.getScaleX() : 0;
    }

    /**
     * 获取 Component 滑动的 Y 轴坐标
     *
     * @param view {@link Component}
     * @return 滑动的 Y 轴坐标
     */
    public static int getScrollY(final Component view) {
        return view != null ? (int) view.getScaleY() : 0;
    }

    // =

    /**
     * 设置 ComponentGroup 和其子控件两者之间的关系
     * <pre>
     *     beforeDescendants : ComponentGroup 会优先其子类控件而获取到焦点
     *     afterDescendants : ComponentGroup 只有当其子类控件不需要获取焦点时才获取焦点
     *     blocksDescendants : ComponentGroup 会覆盖子类控件而直接获得焦点
     *     descendantFocusability="blocksDescendants"
     * </pre>
     *
     * @param viewGroup {@link ComponentContainer}
     * @param <T>       泛型
     * @return {@link ComponentContainer}
     */
    public static <T extends ComponentContainer> T setDescendantFocusability(
            final T viewGroup,
            final int focusability
    ) {
        try {
            if (viewGroup != null) viewGroup.setFocusOrder(focusability);
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "setDescendantFocusability");
        }
        return viewGroup;
    }

//    /**
//     * 设置 Component 滚动模式
//     * <pre>
//     *     设置滑动到边缘时无效果模式 {@link Component#OVER_SCROLL_NEVER}
//     *     overScrollMode="never"
//     * </pre>
//     * @param view           {@link Component}
//     * @param overScrollMode {@link Component#OVER_SCROLL_ALWAYS}、{@link Component#OVER_SCROLL_IF_CONTENT_SCROLLS}、{@link Component#OVER_SCROLL_NEVER}
//     * @param <T>            泛型
//     * @return {@link Component}
//     */
//    public static <T extends Component> T setOverScrollMode(
//            final T view,
//            final int overScrollMode
//    ) {
//        try {
//            if (view != null) view.setOverScrollMode(overScrollMode);
//        } catch (Exception e) {
//            LogPrintUtils.eTag(TAG, e, "setOverScrollMode");
//        }
//        return view;
//    }
//
//    // =
//
//    /**
//     * 是否绘制横向滚动条
//     * @param view {@link Component}
//     * @return {@code true} yes, {@code false} no
//     */
//    public static boolean isHorizontalScrollBarEnabled(final Component view) {
//        return (view != null) && view.isHorizontalScrollBarEnabled();
//    }
//
//    /**
//     * 设置是否绘制横向滚动条
//     * @param view                       {@link Component}
//     * @param horizontalScrollBarEnabled {@code true} yes, {@code false} no
//     * @return {@link Component}
//     */
//    public static Component setHorizontalScrollBarEnabled(
//            final Component view,
//            final boolean horizontalScrollBarEnabled
//    ) {
//        if (view != null) view.setHorizontalScrollBarEnabled(horizontalScrollBarEnabled);
//        return view;
//    }
//
//    /**
//     * 是否绘制垂直滚动条
//     * @param view {@link Component}
//     * @return {@code true} yes, {@code false} no
//     */
//    public static boolean isVerticalScrollBarEnabled(final Component view) {
//        return (view != null) && view.isVerticalScrollBarEnabled();
//    }
//
//    /**
//     * 设置是否绘制垂直滚动条
//     * @param view                     {@link Component}
//     * @param verticalScrollBarEnabled {@code true} yes, {@code false} no
//     * @return {@link Component}
//     */
//    public static Component setVerticalScrollBarEnabled(
//            final Component view,
//            final boolean verticalScrollBarEnabled
//    ) {
//        if (view != null) view.setVerticalScrollBarEnabled(verticalScrollBarEnabled);
//        return view;
//    }

    // =

//    /**
//     * 获取 Component 是否需要滚动效应
//     * @param view {@link Component}
//     * @return {@code true} yes, {@code false} no
//     */
//    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
//    public static boolean isScrollContainer(final Component view) {
//        if (view != null) {
//            return view.isScrollContainer();
//        }
//        return false;
//    }
//
//    /**
//     * 设置 Component 滚动效应
//     * @param view              {@link Component}
//     * @param isScrollContainer 是否需要滚动效应
//     * @return {@link Component}
//     */
//    public static Component setScrollContainer(
//            final Component view,
//            final boolean isScrollContainer
//    ) {
//        if (view != null) {
//            view.setScrollContainer(isScrollContainer);
//        }
//        return view;
//    }

    // =

//    /**
//     * 下一个获取焦点的 Component id
//     * @param view {@link Component}
//     * @return 下一个获取焦点的 Component id
//     */
//    public static int getNextFocusForwardId(final Component view) {
//        if (view != null) {
//            return view.getNextFocusForwardId();
//        }
//        return 0;
//    }

//    /**
//     * 设置下一个获取焦点的 Component id
//     * @param view               {@link Component}
//     * @param nextFocusForwardId 下一个获取焦点的 Component id
//     * @return {@link Component}
//     */
//    public static Component setNextFocusForwardId(
//            final Component view,
//             final int nextFocusForwardId
//    ) {
//        if (view != null) {
//            view.setNextFocusForwardId(nextFocusForwardId);
//        }
//        return view;
//    }

    // =

//    /**
//     * 向下移动焦点时, 下一个获取焦点的 Component id
//     * @param view {@link Component}
//     * @return 向下移动焦点时, 下一个获取焦点的 Component id
//     */
//    public static int getNextFocusDownId(final Component view) {
//        if (view != null) {
//            return view.getNextFocusDownId();
//        }
//        return 0;
//    }
//
//    /**
//     * 设置向下移动焦点时, 下一个获取焦点的 Component id
//     * @param view            {@link Component}
//     * @param nextFocusDownId 下一个获取焦点的 Component id
//     * @return {@link Component}
//     */
//    public static Component setNextFocusDownId(
//            final Component view,
//             final int nextFocusDownId
//    ) {
//        if (view != null) {
//            view.setNextFocusDownId(nextFocusDownId);
//        }
//        return view;
//    }
//
//    // =
//
//    /**
//     * 向左移动焦点时, 下一个获取焦点的 Component id
//     * @param view {@link Component}
//     * @return 向左移动焦点时, 下一个获取焦点的 Component id
//     */
//    public static int getNextFocusLeftId(final Component view) {
//        if (view != null) {
//            return view.getNextFocusLeftId();
//        }
//        return 0;
//    }
//
//    /**
//     * 设置向左移动焦点时, 下一个获取焦点的 Component id
//     * @param view            {@link Component}
//     * @param nextFocusLeftId 下一个获取焦点的 Component id
//     * @return {@link Component}
//     */
//    public static Component setNextFocusLeftId(
//            final Component view,
//             final int nextFocusLeftId
//    ) {
//        if (view != null) {
//            view.setNextFocusLeftId(nextFocusLeftId);
//        }
//        return view;
//    }
//
//    // =
//
//    /**
//     * 向右移动焦点时, 下一个获取焦点的 Component id
//     * @param view {@link Component}
//     * @return 向右移动焦点时, 下一个获取焦点的 Component id
//     */
//    public static int getNextFocusRightId(final Component view) {
//        if (view != null) {
//            return view.getNextFocusRightId();
//        }
//        return 0;
//    }
//
//    /**
//     * 设置向右移动焦点时, 下一个获取焦点的 Component id
//     * @param view             {@link Component}
//     * @param nextFocusRightId 下一个获取焦点的 Component id
//     * @return {@link Component}
//     */
//    public static Component setNextFocusRightId(
//            final Component view,
//             final int nextFocusRightId
//    ) {
//        if (view != null) {
//            view.setNextFocusRightId(nextFocusRightId);
//        }
//        return view;
//    }
//
//    // =
//
//    /**
//     * 向上移动焦点时, 下一个获取焦点的 Component id
//     * @param view {@link Component}
//     * @return 向上移动焦点时, 下一个获取焦点的 Component id
//     */
//    public static int getNextFocusUpId(final Component view) {
//        if (view != null) {
//            return view.getNextFocusUpId();
//        }
//        return 0;
//    }
//
//    /**
//     * 设置向上移动焦点时, 下一个获取焦点的 Component id
//     * @param view          {@link Component}
//     * @param nextFocusUpId 下一个获取焦点的 Component id
//     * @return {@link Component}
//     */
//    public static Component setNextFocusUpId(
//            final Component view,
//             final int nextFocusUpId
//    ) {
//        if (view != null) {
//            view.setNextFocusUpId(nextFocusUpId);
//        }
//        return view;
//    }

    // =

    /**
     * 获取 Component 旋转度数
     *
     * @param view {@link Component}
     * @return Component 旋转度数
     */
    public static float getRotation(final Component view) {
        if (view != null) {
            return view.getRotation();
        }
        return 0f;
    }

    /**
     * 设置 Component 旋转度数
     *
     * @param view     {@link Component}
     * @param rotation 旋转度数
     * @return {@link Component}
     */
    public static Component setRotation(
            final Component view,
            final float rotation
    ) {
        if (view != null) {
            view.setRotation(rotation);
        }
        return view;
    }

    // =

//    /**
//     * 获取 Component 水平旋转度数
//     * @param view {@link Component}
//     * @return Component 水平旋转度数
//     */
//    public static float getRotationX(final Component view) {
//        if (view != null) {
//            return view.getRotationX();
//        }
//        return 0f;
//    }
//
//    /**
//     * 设置 Component 水平旋转度数
//     * @param view      {@link Component}
//     * @param rotationX 水平旋转度数
//     * @return {@link Component}
//     */
//    public static Component setRotationX(
//            final Component view,
//            final float rotationX
//    ) {
//        if (view != null) {
//            view.setRotationX(rotationX);
//        }
//        return view;
//    }
//
//    // =
//
//    /**
//     * 获取 Component 竖直旋转度数
//     * @param view {@link Component}
//     * @return Component 竖直旋转度数
//     */
//    public static float getRotationY(final Component view) {
//        if (view != null) {
//            return view.getRotationY();
//        }
//        return 0f;
//    }
//
//    /**
//     * 设置 Component 竖直旋转度数
//     * @param view      {@link Component}
//     * @param rotationY 竖直旋转度数
//     * @return {@link Component}
//     */
//    public static Component setRotationY(
//            final Component view,
//            final float rotationY
//    ) {
//        if (view != null) {
//            view.setRotationY(rotationY);
//        }
//        return view;
//    }

    // =

    /**
     * 获取 Component 水平方向缩放比例
     *
     * @param view Component
     * @return Component 水平方向缩放比例
     */
    public static float getScaleX(final Component view) {
        if (view != null) {
            return view.getScaleX();
        }
        return 0f;
    }

    /**
     * 设置 Component 水平方向缩放比例
     *
     * @param view   Component
     * @param scaleX 水平方向缩放比例
     * @return {@link Component}
     */
    public static Component setScaleX(
            final Component view,
            final float scaleX
    ) {
        if (view != null) {
            view.setScaleX(scaleX);
        }
        return view;
    }

    // =

    /**
     * 获取 Component 竖直方向缩放比例
     *
     * @param view Component
     * @return Component 竖直方向缩放比例
     */
    public static float getScaleY(final Component view) {
        if (view != null) {
            return view.getScaleY();
        }
        return 0f;
    }

    /**
     * 设置 Component 竖直方向缩放比例
     *
     * @param view   Component
     * @param scaleY 竖直方向缩放比例
     * @return {@link Component}
     */
    public static Component setScaleY(
            final Component view,
            final float scaleY
    ) {
        if (view != null) {
            view.setScaleY(scaleY);
        }
        return view;
    }

    // =

//    /**
//     * 获取文本的显示方式
//     * @param view {@link Component}
//     * @return 文本的显示方式
//     */
//    public static int getTextAlignment(final Component view) {
//        if (view != null) {
//            return view.getTextAlignment();
//        }
//        return 0;
//    }
//
//    /**
//     * 设置文本的显示方式
//     * @param view          {@link Component}
//     * @param textAlignment 文本的显示方式
//     * @return {@link Component}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
//    public static Component setTextAlignment(
//            final Component view,
//            final int textAlignment
//    ) {
//        if (view != null) {
//            view.setTextAlignment(textAlignment);
//        }
//        return view;
//    }
//
//    // =
//
//    /**
//     * 获取文本的显示方向
//     * @param view {@link Component}
//     * @return 文本的显示方向
//     */
//    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
//    public static int getTextDirection(final Component view) {
//        if (view != null) {
//            return view.getTextDirection();
//        }
//        return 0;
//    }
//
//    /**
//     * 设置文本的显示方向
//     * @param view          {@link Component}
//     * @param textDirection 文本的显示方向
//     * @return {@link Component}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
//    public static Component setTextDirection(
//            final Component view,
//            final int textDirection
//    ) {
//        if (view != null) {
//            view.setTextDirection(textDirection);
//        }
//        return view;
//    }

    // =

    /**
     * 获取水平方向偏转量
     *
     * @param view {@link Component}
     * @return 水平方向偏转量
     */
    public static float getPivotX(final Component view) {
        if (view != null) {
            return view.getPivotX();
        }
        return 0f;
    }

    /**
     * 设置水平方向偏转量
     *
     * @param view   Component
     * @param pivotX 水平方向偏转量
     * @return {@link Component}
     */
    public static Component setPivotX(
            final Component view,
            final float pivotX
    ) {
        if (view != null) {
            view.setPivotX(pivotX);
        }
        return view;
    }

    // =

    /**
     * 获取竖直方向偏转量
     *
     * @param view {@link Component}
     * @return 竖直方向偏转量
     */
    public static float getPivotY(final Component view) {
        if (view != null) {
            return view.getPivotY();
        }
        return 0f;
    }

    /**
     * 设置竖直方向偏转量
     *
     * @param view   Component
     * @param pivotY 竖直方向偏转量
     * @return {@link Component}
     */
    public static Component setPivotY(
            final Component view,
            final float pivotY
    ) {
        if (view != null) {
            view.setPivotY(pivotY);
        }
        return view;
    }

    // =

    /**
     * 获取水平方向的移动距离
     *
     * @param view {@link Component}
     * @return 水平方向的移动距离
     */
    public static float getTranslationX(final Component view) {
        if (view != null) {
            return view.getTranslationX();
        }
        return 0f;
    }

    /**
     * 设置水平方向的移动距离
     *
     * @param view         {@link Component}
     * @param translationX 水平方向的移动距离
     * @return {@link Component}
     */
    public static Component setTranslationX(
            final Component view,
            final float translationX
    ) {
        if (view != null) {
            view.setTranslationX(translationX);
        }
        return view;
    }

    // =

    /**
     * 获取竖直方向的移动距离
     *
     * @param view {@link Component}
     * @return 竖直方向的移动距离
     */
    public static float getTranslationY(final Component view) {
        if (view != null) {
            return view.getTranslationY();
        }
        return 0f;
    }

    /**
     * 设置竖直方向的移动距离
     *
     * @param view         {@link Component}
     * @param translationY 竖直方向的移动距离
     * @return {@link Component}
     */
    public static Component setTranslationY(
            final Component view,
            final float translationY
    ) {
        if (view != null) {
            view.setTranslationY(translationY);
        }
        return view;
    }

    // =

//    /**
//     * 获取 Component 硬件加速类型
//     * @param view {@link Component}
//     * @return Component 硬件加速类型
//     */
//    public static int getLayerType(final Component view) {
//        if (view != null) {
//            int itemComponentType = BaseItemProvider.getItemComponentType(view.getId());
//            return itemComponentType;
//        }
//        return 0;
//    }

//    /**
//     * 设置 Component 硬件加速类型
//     * @param view      {@link Component}
//     * @param layerType 硬件加速类型
//     * @param paint     {@link Paint}
//     * @return {@link Component}
//     */
//    public static Component setLayerType(
//            final Component view,
//            final int layerType,
//            final Paint paint
//    ) {
//        if (view != null) {
//            view.setLayerType(layerType, paint);
//        }
//        return view;
//    }

    // =

    /**
     * 请求重新对 Component 布局
     *
     * @param view {@link Component}
     * @return {@link Component}
     */
    public static Component requestLayout(final Component view) {
        if (view != null) {
            view.postLayout();
        }
        return view;
    }

//    /**
//     * Component 请求获取焦点
//     * @param view {@link Component}
//     * @return {@link Component}
//     */
//    public static Component requestFocus(final Component view) {
//        if (view != null) {
//            view.requestFocus();
//        }
//        return view;
//    }

//    /**
//     * Component 清除焦点
//     * @param view {@link Component}
//     * @return {@link Component}
//     */
//    public static Component clearFocus(final Component view) {
//        if (view != null) {
//            view.clearFocus();
//        }
//        return view;
//    }

//    /**
//     * 获取 Component 里获取焦点的 Component
//     * @param view {@link Component}
//     * @return {@link Component}
//     */
//    public static Component findFocus(final Component view) {
//        if (view != null) {
//            return view.findFocus();
//        }
//        return null;
//    }

//    /**
//     * 获取是否当前 Component 就是焦点 Component
//     * @param view {@link Component}
//     * @return {@code true} yes, {@code false} no
//     */
//    public static boolean isFocused(final Component view) {
//        if (view != null) {
//            return view.isFocused();
//        }
//        return false;
//    }

//    /**
//     * 获取当前 Component 是否是焦点 Component 或者子 Component 里面有焦点 Component
//     * @param view {@link Component}
//     * @return {@code true} yes, {@code false} no
//     */
//    public static boolean hasFocus(final Component view) {
//        if (view != null) {
//            return view.hasFocus();
//        }
//        return false;
//    }

    /**
     * 获取当前 Component 或者子 Component 是否可以获取焦点
     *
     * @param view {@link Component}
     * @return {@code true} yes, {@code false} no
     */
    public static boolean hasFocusable(final Component view) {
        if (view != null) {
            return view.hasFocus();
        }
        return false;
    }

    // =

    /**
     * 获取 Component 是否在触摸模式下获得焦点
     *
     * @param view {@link Component}
     * @return {@code true} 可获取, {@code false} 不可获取
     */
    public static boolean isFocusableInTouchMode(final Component view) {
        if (view != null) {
            return view.isTouchFocusable();
        }
        return false;
    }

    /**
     * 设置 Component 是否在触摸模式下获得焦点
     *
     * @param focusableInTouchMode {@code true} 可获取, {@code false} 不可获取
     * @param views                Component[]
     * @return {@code true} 可获取, {@code false} 不可获取
     */
    public static boolean setFocusableInTouchMode(
            final boolean focusableInTouchMode,
            final Component... views
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setTouchFocusable(focusableInTouchMode);
                }
            }
        }
        return focusableInTouchMode;
    }

    // =

    /**
     * 获取 Component 是否可以获取焦点
     *
     * @param view {@link Component}
     * @return {@code true} 可获取, {@code false} 不可获取
     */
    public static boolean isFocusable(final Component view) {
        if (view != null) {
            return view.isFocusable();
        }
        return false;
    }

    /**
     * 设置 Component 是否可以获取焦点
     *
     * @param focusable {@code true} 可获取, {@code false} 不可获取
     * @param views     Component[]
     * @return {@code true} 可获取, {@code false} 不可获取
     */
    public static boolean setFocusable(
            final boolean focusable,
            final Component... views
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setTouchFocusable(focusable);
                }
            }
        }
        return focusable;
    }

    /**
     * 切换获取焦点状态
     *
     * @param views Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean toggleFocusable(final Component... views) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setTouchFocusable(!view.isFocusable());
                }
            }
            return true;
        }
        return false;
    }

    // =

    /**
     * 获取 Component 是否选中
     *
     * @param view {@link Component}
     * @return {@code true} 选中, {@code false} 非选中
     */
    public static boolean isSelected(final Component view) {
        if (view != null) {
            return view.isSelected();
        }
        return false;
    }

    /**
     * 设置 Component 是否选中
     *
     * @param selected {@code true} 选中, {@code false} 非选中
     * @param views    Component[]
     * @return {@code true} 选中, {@code false} 非选中
     */
    public static boolean setSelected(
            final boolean selected,
            final Component... views
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setSelected(selected);
                }
            }
        }
        return selected;
    }
    /**
     * 转换 View
     *
     * @param view {@link Component}
     * @param <T>  泛型
     * @return {@link Component}
     */
    public static <T extends Component> T convertView(final Component view) {
        try {
            return (T) view;
        } catch (Exception e) {
            LogUtils.error(TAG, e + "convertView");
        }
        return null;
    }

    /**
     * 切换选中状态
     *
     * @param views Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean toggleSelected(final Component... views) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setSelected(!view.isSelected());
                }
            }
            return true;
        }
        return false;
    }

    // =

    /**
     * 获取 Component 是否启用
     *
     * @param view {@link Component}
     * @return {@code true} 启用, {@code false} 禁用
     */
    public static boolean isEnabled(final Component view) {
        if (view != null) {
            return view.isEnabled();
        }
        return false;
    }

    /**
     * 设置 Component 是否启用
     *
     * @param enabled {@code true} 启用, {@code false} 禁用
     * @param views   Component[]
     * @return {@code true} 启用, {@code false} 禁用
     */
    public static boolean setEnabled(
            final boolean enabled,
            final Component... views
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setEnabled(enabled);
                }
            }
        }
        return enabled;
    }

    /**
     * 切换 Component 是否启用状态
     *
     * @param views Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean toggleEnabled(final Component... views) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setEnabled(!view.isEnabled());
                }
            }
            return true;
        }
        return false;
    }

    // =

    /**
     * 获取 Component 是否可以点击
     *
     * @param view {@link Component}
     * @return {@code true} 可点击, {@code false} 不可点击
     */
    public static boolean isClickable(final Component view) {
        if (view != null) {
            return view.isClickable();
        }
        return false;
    }

    /**
     * 设置 Component 是否可以点击
     *
     * @param clickable {@code true} 可点击, {@code false} 不可点击
     * @param views     Component[]
     * @return {@code true} 可点击, {@code false} 不可点击
     */
    public static boolean setClickable(
            final boolean clickable,
            final Component... views
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setClickable(clickable);
                }
            }
        }
        return clickable;
    }

    /**
     * 切换 Component 是否可以点击状态
     *
     * @param views Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean toggleClickable(final Component... views) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setClickable(!view.isClickable());
                }
            }
            return true;
        }
        return false;
    }

    // =

    /**
     * 获取 Component 是否可以长按
     *
     * @param view {@link Component}
     * @return {@code true} 可长按, {@code false} 不可长按
     */
    public static boolean isLongClickable(final Component view) {
        if (view != null) {
            return view.isLongClickOn();
        }
        return false;
    }

    /**
     * 设置 Component 是否可以长按
     *
     * @param longClickable {@code true} 可长按, {@code false} 不可长按
     * @param views         Component[]
     * @return {@code true} 可长按, {@code false} 不可长按
     */
    public static boolean setLongClickable(
            final boolean longClickable,
            final Component... views
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setLongClickable(longClickable);
                }
            }
        }
        return longClickable;
    }

    /**
     * 切换 Component 是否可以长按状态
     *
     * @param views Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean toggleLongClickable(final Component... views) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setLongClickable(!view.isLongClickOn());
                }
            }
            return true;
        }
        return false;
    }

    // ================
    // = Component 显示状态 =
    // ================

    /**
     * 判断 Component 是否显示 ( 如果存在父级则判断父级 )
     * <pre>
     *     需要父布局已展示到 Window 上
     * </pre>
     *
     * @param view {@link Component}
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isShown(final Component view) {
        return (view != null) && view.isComponentDisplayed();
    }

    /**
     * 判断 Component 是否都显示 ( 如果存在父级则判断父级 )
     *
     * @param views Component[]
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isShowns(final Component... views) {
        if (views != null && views.length != 0) {
            for (int i = 0, len = views.length; i < len; i++) {
                if (!isShown(views[i])) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    // =

    /**
     * 判断 Component 是否显示
     *
     * @param view {@link Component}
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isVisibility(final Component view) {
        return isVisibility(view, true);
    }

    /**
     * 判断 Component 是否显示
     *
     * @param view         {@link Component}
     * @param defaultValue view 为 null 默认值
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isVisibility(
            final Component view,
            final boolean defaultValue
    ) {
        if (view != null) {
            return (view.getVisibility() == Component.VISIBLE);
        }
        return defaultValue;
    }

    /**
     * 判断 Component 是否都显示
     *
     * @param views Component[]
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isVisibilitys(final Component... views) {
        if (views != null && views.length != 0) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view == null || view.getVisibility() != Component.VISIBLE) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    // =

    /**
     * 判断 Component 是否隐藏占位
     *
     * @param view {@link Component}
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isVisibilityIN(final Component view) {
        return isVisibilityIN(view, false);
    }

    /**
     * 判断 Component 是否隐藏占位
     *
     * @param view         {@link Component}
     * @param defaultValue view 为 null 默认值
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isVisibilityIN(
            final Component view,
            final boolean defaultValue
    ) {
        if (view != null) {
            return (view.getVisibility() == Component.INVISIBLE);
        }
        return defaultValue;
    }

    /**
     * 判断 Component 是否都隐藏占位
     *
     * @param views Component[]
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isVisibilityINs(final Component... views) {
        if (views != null && views.length != 0) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view == null || view.getVisibility() != Component.INVISIBLE) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    // =

    /**
     * 判断 Component 是否隐藏
     *
     * @param view {@link Component}
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isVisibilityGone(final Component view) {
        return isVisibilityGone(view, false);
    }

    /**
     * 判断 Component 是否隐藏
     *
     * @param view         {@link Component}
     * @param defaultValue view 为 null 默认值
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isVisibilityGone(
            final Component view,
            final boolean defaultValue
    ) {
        if (view != null) {
            return (view.getVisibility() == Component.HIDE);
        }
        return defaultValue;
    }

    /**
     * 判断 Component 是否都隐藏
     *
     * @param views Component[]
     * @return {@code true} yes, {@code false} no
     */
    public static boolean isVisibilityGones(final Component... views) {
        if (views != null && views.length != 0) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view == null || view.getVisibility() != Component.HIDE) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    // =

    /**
     * 获取显示的状态 (Component.VISIBLE : Component.GONE)
     *
     * @param isVisibility {@code true} Component.VISIBLE, {@code false} Component.GONE
     * @return 显示的状态 {@link Component#VISIBLE}、{@link Component#HIDE}
     */
    public static int getVisibility(final boolean isVisibility) {
        return isVisibility ? Component.VISIBLE : Component.HIDE;
    }

    /**
     * 获取显示的状态 (Component.VISIBLE : Component.INVISIBLE)
     *
     * @param isVisibility {@code true} Component.VISIBLE, {@code false} Component.INVISIBLE
     * @return 显示的状态 {@link Component#VISIBLE}、{@link Component#INVISIBLE}
     */
    public static int getVisibilityIN(final boolean isVisibility) {
        return isVisibility ? Component.VISIBLE : Component.INVISIBLE;
    }

    // =

    /**
     * 设置 Component 显示的状态
     *
     * @param isVisibility {@code true} Component.VISIBLE, {@code false} Component.GONE
     * @param view         {@link Component}
     * @return isVisibility
     */
    public static boolean setVisibility(
            final boolean isVisibility,
            final Component view
    ) {
        if (view != null) {
            view.setVisibility(isVisibility ? Component.VISIBLE : Component.HIDE);
        }
        return isVisibility;
    }

    /**
     * 设置 Component 显示的状态
     *
     * @param isVisibility {@link Component#VISIBLE}、{@link Component#INVISIBLE}、{@link Component#HIDE}
     * @param view         {@link Component}
     * @return isVisibility 是否传入 {@link Component#VISIBLE}
     */
    public static boolean setVisibility(
            final int isVisibility,
            final Component view
    ) {
        if (view != null) {
            view.setVisibility(isVisibility);
        }
        return (isVisibility == Component.VISIBLE);
    }

    // =

    /**
     * 设置 Component 显示的状态
     *
     * @param isVisibility {@code true} Component.VISIBLE, {@code false} Component.GONE
     * @param views        Component[]
     * @return isVisibility 是否传入 {@link Component#VISIBLE}
     */
    public static boolean setVisibilitys(
            final boolean isVisibility,
            final Component... views
    ) {
        return setVisibilitys(getVisibility(isVisibility), views);
    }

    /**
     * 设置 Component 显示的状态
     *
     * @param isVisibility {@link Component#VISIBLE}、{@link Component#INVISIBLE}、{@link Component#HIDE}
     * @param views        Component[]
     * @return isVisibility 是否传入 {@link Component#VISIBLE}
     */
    public static boolean setVisibilitys(
            final int isVisibility,
            final Component... views
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setVisibility(isVisibility);
                }
            }
        }
        return (isVisibility == Component.VISIBLE);
    }

    // =

    /**
     * 切换 Component 显示的状态
     *
     * @param view  {@link Component}
     * @param views Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean toggleVisibilitys(
            final Component view,
            final Component... views
    ) {
        if (view != null) {
            view.setVisibility(Component.VISIBLE);
        }
        setVisibilitys(Component.HIDE, views);
        return true;
    }

    /**
     * 切换 Component 显示的状态
     *
     * @param viewArys Component[]
     * @param views    Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean toggleVisibilitys(
            final Component[] viewArys,
            final Component... views
    ) {
        return toggleVisibilitys(Component.HIDE, viewArys, views);
    }

    /**
     * 切换 Component 显示的状态
     *
     * @param state    {@link Component#VISIBLE}、{@link Component#INVISIBLE}、{@link Component#HIDE}
     * @param viewArys Component[]
     * @param views    Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean toggleVisibilitys(
            final int state,
            final Component[] viewArys,
            final Component... views
    ) {
        // 默认显示
        setVisibilitys(Component.VISIBLE, viewArys);
        // 根据状态处理
        setVisibilitys(state, views);
        return true;
    }

    // =

    /**
     * 反转 Component 显示的状态
     *
     * @param state    {@link Component#VISIBLE}、{@link Component#INVISIBLE}、{@link Component#HIDE}
     * @param viewArys Component[]
     * @param views    Component[]
     * @return isVisibility
     */
    public static boolean reverseVisibilitys(
            final int state,
            final Component[] viewArys,
            final Component... views
    ) {
        return reverseVisibilitys(state == Component.VISIBLE, viewArys, views);
    }

    /**
     * 反转 Component 显示的状态
     *
     * @param isVisibility {@code true} Component.VISIBLE, {@code false} Component.GONE
     * @param viewArys     Component[]
     * @param views        Component[]
     * @return isVisibility
     */
    public static boolean reverseVisibilitys(
            final boolean isVisibility,
            final Component[] viewArys,
            final Component... views
    ) {
        // 默认处理第一个数组
        setVisibilitys(isVisibility, viewArys);
        // 根据状态处理
        setVisibilitys(!isVisibility, views);
        return isVisibility;
    }

    /**
     * 反转 Component 显示的状态
     *
     * @param state {@link Component#VISIBLE}、{@link Component#INVISIBLE}、{@link Component#HIDE}
     * @param view  {@link Component}
     * @param views Component[]
     * @return isVisibility
     */
    public static boolean reverseVisibilitys(
            final int state,
            final Component view,
            final Component... views
    ) {
        return reverseVisibilitys(state == Component.VISIBLE, view, views);
    }

    /**
     * 反转 Component 显示的状态
     *
     * @param isVisibility {@code true} Component.VISIBLE, {@code false} Component.GONE
     * @param view         {@link Component}
     * @param views        Component[]
     * @return isVisibility
     */
    public static boolean reverseVisibilitys(
            final boolean isVisibility,
            final Component view,
            final Component... views
    ) {
        // 默认处理第一个 Component
        setVisibilitys(isVisibility, view);
        // 根据状态处理
        setVisibilitys(!isVisibility, views);
        return isVisibility;
    }

    // =

    /**
     * 切换 Component 状态
     *
     * @param isChange     是否改变
     * @param isVisibility {@link Component#VISIBLE}、{@link Component#INVISIBLE}、{@link Component#HIDE}
     * @param view         {@link Component}
     * @return isChange
     */
    public static boolean toggleComponent(
            final boolean isChange,
            final int isVisibility,
            final Component view
    ) {
        if (isChange && view != null) {
            view.setVisibility(isVisibility);
        }
        return isChange;
    }

    /**
     * 切换 Component 状态
     *
     * @param isChange     是否改变
     * @param isVisibility {@link Component#VISIBLE}、{@link Component#INVISIBLE}、{@link Component#HIDE}
     * @param views        Component[]
     * @return isChange
     */
    public static boolean toggleComponents(
            final boolean isChange,
            final int isVisibility,
            final Component... views
    ) {
        if (isChange && views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                Component view = views[i];
                if (view != null) {
                    view.setVisibility(isVisibility);
                }
            }
        }
        return isChange;
    }

    // =

    /**
     * 把自身从父 Component 中移除
     *
     * @param view {@link Component}
     * @return {@link Component}
     */
    public static Component removeSelfFromParent(final Component view) {
        if (view != null) {
            try {
                ComponentParent parent = view.getComponentParent();
                if (parent instanceof ComponentParent) {
                    ComponentParent group = (ComponentParent) parent;
                    group.removeComponent(view);
                }
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "removeSelfFromParent");
            }
        }
        return view;
    }

//    /**
//     * 判断触点是否落在该 Component 上
//     * @param ev   {@link KeyEvent}
//     * @param view 待判断 {@link Component}
//     * @return {@code true} yes, {@code false} no
//     */
//    public static boolean isTouchInComponent(
//            final KeyEvent ev,
//            final Component view
//    ) {
//        if (ev != null && view != null) {
//            int[] locations =view.getLocationOnScreen();
//            float motionX = ev.getRawX();
//            float motionY = ev.getRawY();
//            return motionX >= locations[0] && motionX <= (locations[0] + view.getWidth())
//                    && motionY >= locations[1] && motionY <= (locations[1] + view.getHeight());
//        }
//        return false;
//    }

//    /**
//     * Component 请求更新
//     * @param view      {@link Component}
//     * @param allParent 是否全部父布局 Component 都请求
//     * @return {@link Component}
//     */
//    public static Component requestLayoutParent(
//            final Component view,
//            final boolean allParent
//    ) {
//        if (view != null) {
//            ComponentParent parent = view.getComponentParent();
//            while (parent instanceof Component) {
//                if (!parent.isLayoutRequested()) {
//                    parent.requestLayout();
//                    if (!allParent) {
//                        break;
//                    }
//                }
//                parent = parent.getParent();
//            }
//        }
//        return view;
//    }

//    /**
//     * 测量 Component
//     * @param view {@link Component}
//     * @return int[] 0 = 宽度, 1 = 高度
//     */
//    public static int[] measureComponent(final Component view) {
//        return WidgetUtils.measureComponent(view);
//    }
//
//    /**
//     * 获取 Component 的宽度
//     * @param view {@link Component}
//     * @return Component 的宽度
//     */
//    public static int getMeasuredWidth(final Component view) {
//        return WidgetUtils.getMeasuredWidth(view);
//    }
//
//    /**
//     * 获取 Component 的高度
//     * @param view {@link Component}
//     * @return Component 的高度
//     */
//    public static int getMeasuredHeight(final Component view) {
//        return WidgetUtils.getMeasuredHeight(view);
//    }
//
//    /**
//     * 测量 Component
//     * @param view           {@link Component}
//     * @param specifiedWidth 指定宽度
//     * @return {@code true} success, {@code false} fail
//     */
//    public static boolean measureComponent(
//            final Component view,
//            final int specifiedWidth
//    ) {
//        return WidgetUtils.measureComponent(view, specifiedWidth);
//    }
//
//    /**
//     * 测量 Component
//     * @param view            {@link Component}
//     * @param specifiedWidth  指定宽度
//     * @param specifiedHeight 指定高度
//     * @return {@code true} success, {@code false} fail
//     */
//    public static boolean measureComponent(
//            final Component view,
//            final int specifiedWidth,
//            final int specifiedHeight
//    ) {
//        return WidgetUtils.measureComponent(view, specifiedWidth, specifiedHeight);
//    }

    // ==================
    // = Layout Gravity =
    // ==================

    /**
     * 获取 Component Layout Gravity
     *
     * @param view {@link Component}
     * @return Layout Gravity
     */
    public static int getLayoutGravity(final Component view) {
        return getLayoutGravity(view, true);
    }

    /**
     * 获取 Component Layout Gravity
     *
     * @param view         {@link Component}
     * @param isReflection 是否使用反射
     * @return Layout Gravity
     */
    public static int getLayoutGravity(
            final Component view,
            final boolean isReflection
    ) {
        if (view != null && view.getLayoutConfig() != null) {
            try {
                ComponentContainer.LayoutConfig layoutParams = view.getLayoutConfig();
                if (layoutParams instanceof DirectionalLayout.LayoutConfig) {
                    return ((DirectionalLayout.LayoutConfig) layoutParams).alignment;
                } else if ((layoutParams instanceof StackLayout.LayoutConfig)) {
                    return ((StackLayout.LayoutConfig) layoutParams).alignment;
                }
                if (isReflection) {
                    Field[] fields = FieldUtils.getFields(layoutParams);
                    for (Field field : fields) {
                        if (field.getName().equals("alignment")) {
                            return (int) field.get(layoutParams);
                        }
                    }
                }
                // 抛出不支持的类型
                throw new Exception("layoutParams:" + layoutParams.toString());
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "getLayoutGravity");
            }
        }
        return 0;
    }

    /**
     * 设置 Component Layout Gravity
     *
     * @param view    {@link Component}
     * @param gravity Gravity
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setLayoutGravity(
            final Component view,
            final int gravity
    ) {
        return setLayoutGravity(view, gravity, true);
    }

    /**
     * 设置 Component Layout Gravity
     *
     * @param view         {@link Component}
     * @param gravity      Gravity
     * @param isReflection 是否使用反射
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setLayoutGravity(
            final Component view,
            final int gravity,
            final boolean isReflection
    ) {
        if (view != null && view.getLayoutConfig() != null) {
            try {
                ComponentContainer.LayoutConfig layoutParams = view.getLayoutConfig();
                if (layoutParams instanceof DirectionalLayout.LayoutConfig) {
                    ((DirectionalLayout.LayoutConfig) layoutParams).alignment = gravity;
                    view.setLayoutConfig(layoutParams);
                    return true;
                } else if ((layoutParams instanceof StackLayout.LayoutConfig)) {
                    ((StackLayout.LayoutConfig) layoutParams).alignment = gravity;
                    view.setLayoutConfig(layoutParams);
                    return true;
                }
                if (isReflection) {
                    Field[] fields = FieldUtils.getFields(layoutParams);
                    for (Field field : fields) {
                        if (field.getName().equals("gravity")) {
                            field.set(layoutParams, gravity);
                            view.setLayoutConfig(layoutParams);
                            return true;
                        }
                    }
                }
                // 抛出不支持的类型
                throw new Exception("layoutParams:" + layoutParams.toString());
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "setLayoutGravity");
            }
        }
        return false;
    }

    // ===============
    // = Component Margin =
    // ===============

    /**
     * 获取 Component Left Margin
     *
     * @param view {@link Component}
     * @return Left Margin
     */
    public static int getMarginLeft(final Component view) {
        return getMargin(view)[0];
    }

    /**
     * 获取 Component Top Margin
     *
     * @param view {@link Component}
     * @return Top Margin
     */
    public static int getMarginTop(final Component view) {
        return getMargin(view)[1];
    }

    /**
     * 获取 Component Right Margin
     *
     * @param view {@link Component}
     * @return Right Margin
     */
    public static int getMarginRight(final Component view) {
        return getMargin(view)[2];
    }

    /**
     * 获取 Component Bottom Margin
     *
     * @param view {@link Component}
     * @return Bottom Margin
     */
    public static int getMarginBottom(final Component view) {
        return getMargin(view)[3];
    }

    /**
     * 获取 Component Margin
     *
     * @param view {@link Component}
     * @return new int[] {left, top, right, bottom}
     */
    public static int[] getMargin(final Component view) {
        int[] margin = new int[]{0, 0, 0, 0};
        if (view != null && view.getLayoutConfig() != null) {
            if (view.getLayoutConfig() instanceof ComponentContainer.LayoutConfig) {
                ComponentContainer.LayoutConfig layoutParams = (ComponentContainer.LayoutConfig) view.getLayoutConfig();
                margin[0] = layoutParams.getMarginLeft();
                margin[1] = layoutParams.getMarginTop();
                margin[2] = layoutParams.getMarginRight();
                margin[3] = layoutParams.getMarginBottom();
            }
        }
        return margin;
    }

    // =

    /**
     * 设置 Component Left Margin
     *
     * @param view       {@link Component}
     * @param leftMargin Left Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMarginLeft(
            final Component view,
            final int leftMargin
    ) {
        return setMarginLeft(view, leftMargin, true);
    }

    /**
     * 设置 Component Left Margin
     *
     * @param view       {@link Component}
     * @param leftMargin Left Margin
     * @param reset      是否重置清空其他 margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMarginLeft(
            final Component view,
            final int leftMargin,
            final boolean reset
    ) {
        if (reset) return setMargin(view, leftMargin, 0, 0, 0);
        int[] margin = getMargin(view);
        return setMargin(view, leftMargin, margin[1], margin[2], margin[3]);
    }

    /**
     * 设置 Component Top Margin
     *
     * @param view      {@link Component}
     * @param topMargin Top Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMarginTop(
            final Component view,
            final int topMargin
    ) {
        return setMarginTop(view, topMargin, true);
    }
    /**
     * 设置 Component Top Margin
     *
     * @param targetView    {@link Component}
     * @param topMargin Top Margin
     * @return {@code true} success, {@code false} fail
     */
    public static void setMarginTop(int topMargin, Component targetView) {
        if (targetView != null) {
            targetView.setMarginTop(topMargin);
        }
    }
    /**
     * 设置 Component Lift Margin
     *
     * @param targetView    {@link Component}
     * @param leftMargin Lift Margin
     * @return {@code true} success, {@code false} fail
     */
    public static void setMarginLeft(int leftMargin, Component targetView) {
        if (targetView != null) {
            targetView.setMarginLeft(leftMargin);
        }
    }
    /**
     * 设置 Component Top Margin
     *
     * @param view      {@link Component}
     * @param topMargin Top Margin
     * @param reset     是否重置清空其他 margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMarginTop(
            final Component view,
            final int topMargin,
            final boolean reset
    ) {
        if (reset) return setMargin(view, 0, topMargin, 0, 0);
        int[] margin = getMargin(view);
        return setMargin(view, margin[0], topMargin, margin[2], margin[3]);
    }

    /**
     * 设置 Component Right Margin
     *
     * @param view        {@link Component}
     * @param rightMargin Right Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMarginRight(
            final Component view,
            final int rightMargin
    ) {
        return setMarginRight(view, rightMargin, true);
    }

    /**
     * 设置 Component Right Margin
     *
     * @param view        {@link Component}
     * @param rightMargin Right Margin
     * @param reset       是否重置清空其他 margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMarginRight(
            final Component view,
            final int rightMargin,
            final boolean reset
    ) {
        if (reset) return setMargin(view, 0, 0, rightMargin, 0);
        int[] margin = getMargin(view);
        return setMargin(view, margin[0], margin[1], rightMargin, margin[3]);
    }

    /**
     * 设置 Component Bottom Margin
     *
     * @param view         {@link Component}
     * @param bottomMargin Bottom Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMarginBottom(
            final Component view,
            final int bottomMargin
    ) {
        return setMarginBottom(view, bottomMargin, true);
    }

    /**
     * 设置 Component Bottom Margin
     *
     * @param view         {@link Component}
     * @param bottomMargin Bottom Margin
     * @param reset        是否重置清空其他 margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMarginBottom(
            final Component view,
            final int bottomMargin,
            final boolean reset
    ) {
        if (reset) return setMargin(view, 0, 0, 0, bottomMargin);
        int[] margin = getMargin(view);
        return setMargin(view, margin[0], margin[1], margin[2], bottomMargin);
    }

    /**
     * 设置 Margin 边距
     *
     * @param view      {@link Component}
     * @param leftRight Left and Right Margin
     * @param topBottom Top and bottom Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMargin(
            final Component view,
            final int leftRight,
            final int topBottom
    ) {
        return setMargin(view, leftRight, topBottom, leftRight, topBottom);
    }

    /**
     * 设置 Margin 边距
     *
     * @param view   {@link Component}
     * @param margin Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMargin(
            final Component view,
            final int margin
    ) {
        return setMargin(view, margin, margin, margin, margin);
    }

    /**
     * 设置 Margin 边距
     *
     * @param view   {@link Component}
     * @param left   Left Margin
     * @param top    Top Margin
     * @param right  Right Margin
     * @param bottom Bottom Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMargin(
            final Component view,
            final int left,
            final int top,
            final int right,
            final int bottom
    ) {
        if (view != null && view.getLayoutConfig() != null) {
            if (view.getLayoutConfig() instanceof ComponentContainer.LayoutConfig) {
                ComponentContainer.LayoutConfig layoutParams = (ComponentContainer.LayoutConfig) view.getLayoutConfig();
                layoutParams.setMargins(left, top, right, bottom);
                view.setLayoutConfig(layoutParams);
                return true;
            }
        }
        return false;
    }

    // =

    /**
     * 设置 Margin 边距
     *
     * @param views     Component[]
     * @param leftRight Left and Right Margin
     * @param topBottom Top and bottom Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMargin(
            final Component[] views,
            final int leftRight,
            final int topBottom
    ) {
        return setMargin(views, leftRight, topBottom, leftRight, topBottom);
    }

    /**
     * 设置 Margin 边距
     *
     * @param views  Component[]
     * @param margin Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMargin(
            final Component[] views,
            final int margin
    ) {
        return setMargin(views, margin, margin, margin, margin);
    }

    /**
     * 设置 Margin 边距
     *
     * @param views  Component[]
     * @param left   Left Margin
     * @param top    Top Margin
     * @param right  Right Margin
     * @param bottom Bottom Margin
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setMargin(
            final Component[] views,
            final int left,
            final int top,
            final int right,
            final int bottom
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                setMargin(views[i], left, top, right, bottom);
            }
            return true;
        }
        return false;
    }

    // ================
    // = Component Padding =
    // ================

    /**
     * 获取 Component Left Padding
     *
     * @param view {@link Component}
     * @return Left Padding
     */
    public static int getPaddingLeft(final Component view) {
        return getPadding(view)[0];
    }

    /**
     * 获取 Component Top Padding
     *
     * @param view {@link Component}
     * @return Top Padding
     */
    public static int getPaddingTop(final Component view) {
        return getPadding(view)[1];
    }

    /**
     * 获取 Component Right Padding
     *
     * @param view {@link Component}
     * @return Right Padding
     */
    public static int getPaddingRight(final Component view) {
        return getPadding(view)[2];
    }

    /**
     * 获取 Component Bottom Padding
     *
     * @param view {@link Component}
     * @return Bottom Padding
     */
    public static int getPaddingBottom(final Component view) {
        return getPadding(view)[3];
    }

    /**
     * 获取 Component Padding
     *
     * @param view {@link Component}
     * @return new int[] {left, top, right, bottom}
     */
    public static int[] getPadding(final Component view) {
        int[] padding = new int[]{0, 0, 0, 0};
        if (view != null) {
            padding[0] = view.getPaddingLeft();
            padding[1] = view.getPaddingTop();
            padding[2] = view.getPaddingRight();
            padding[3] = view.getPaddingBottom();
        }
        return padding;
    }

    // =

    /**
     * 设置 Component Left Padding
     *
     * @param view        {@link Component}
     * @param leftPadding Left Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPaddingLeft(
            final Component view,
            final int leftPadding
    ) {
        return setPaddingLeft(view, leftPadding, true);
    }

    /**
     * 设置 Component Left Padding
     *
     * @param view        {@link Component}
     * @param leftPadding Left Padding
     * @param reset       是否重置清空其他 Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPaddingLeft(
            final Component view,
            final int leftPadding,
            final boolean reset
    ) {
        if (reset) return setPadding(view, leftPadding, 0, 0, 0);
        int[] padding = getPadding(view);
        return setPadding(view, leftPadding, padding[1], padding[2], padding[3]);
    }

    /**
     * 设置 Component Top Padding
     *
     * @param view       {@link Component}
     * @param topPadding Top Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPaddingTop(
            final Component view,
            final int topPadding
    ) {
        return setPaddingTop(view, topPadding, true);
    }

    /**
     * 设置 Component Top Padding
     *
     * @param view       {@link Component}
     * @param topPadding Top Padding
     * @param reset      是否重置清空其他 Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPaddingTop(
            final Component view,
            final int topPadding,
            final boolean reset
    ) {
        if (reset) return setPadding(view, 0, topPadding, 0, 0);
        int[] padding = getPadding(view);
        return setPadding(view, padding[0], topPadding, padding[2], padding[3]);
    }

    /**
     * 设置 Component Right Padding
     *
     * @param view         {@link Component}
     * @param rightPadding Right Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPaddingRight(
            final Component view,
            final int rightPadding
    ) {
        return setPaddingRight(view, rightPadding, true);
    }

    /**
     * 设置 Component Right Padding
     *
     * @param view         {@link Component}
     * @param rightPadding Right Padding
     * @param reset        是否重置清空其他 Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPaddingRight(
            final Component view,
            final int rightPadding,
            final boolean reset
    ) {
        if (reset) return setPadding(view, 0, 0, rightPadding, 0);
        int[] padding = getPadding(view);
        return setPadding(view, padding[0], padding[1], rightPadding, padding[3]);
    }

    /**
     * 设置 Component Bottom Padding
     *
     * @param view          {@link Component}
     * @param bottomPadding Bottom Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPaddingBottom(
            final Component view,
            final int bottomPadding
    ) {
        return setPaddingBottom(view, bottomPadding, true);
    }

    /**
     * 设置 Component Bottom Padding
     *
     * @param view          {@link Component}
     * @param bottomPadding Bottom Padding
     * @param reset         是否重置清空其他 Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPaddingBottom(
            final Component view,
            final int bottomPadding,
            final boolean reset
    ) {
        if (reset) return setPadding(view, 0, 0, 0, bottomPadding);
        int[] padding = getPadding(view);
        return setPadding(view, padding[0], padding[1], padding[2], bottomPadding);
    }

    /**
     * 设置 Padding 边距
     *
     * @param view      {@link Component}
     * @param leftRight Left and Right Padding
     * @param topBottom Top and bottom Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPadding(
            final Component view,
            final int leftRight,
            final int topBottom
    ) {
        return setPadding(view, leftRight, topBottom, leftRight, topBottom);
    }

    /**
     * 设置 Padding 边距
     *
     * @param view    {@link Component}
     * @param padding Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPadding(
            final Component view,
            final int padding
    ) {
        return setPadding(view, padding, padding, padding, padding);
    }

    /**
     * 设置 Padding 边距
     *
     * @param view   {@link Component}
     * @param left   Left Padding
     * @param top    Top Padding
     * @param right  Right Padding
     * @param bottom Bottom Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPadding(
            final Component view,
            final int left,
            final int top,
            final int right,
            final int bottom
    ) {
        if (view != null) {
            view.setPadding(left, top, right, bottom);
            return true;
        }
        return false;
    }

    // =

    /**
     * 设置 Padding 边距
     *
     * @param views     Component[]
     * @param leftRight Left and Right Padding
     * @param topBottom Top and bottom Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPadding(
            final Component[] views,
            final int leftRight,
            final int topBottom
    ) {
        return setPadding(views, leftRight, topBottom, leftRight, topBottom);
    }

    /**
     * 设置 Padding 边距
     *
     * @param views   Component[]
     * @param padding Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPadding(
            final Component[] views,
            final int padding
    ) {
        return setPadding(views, padding, padding, padding, padding);
    }

    /**
     * 设置 Padding 边距
     *
     * @param views  Component[]
     * @param left   Left Padding
     * @param top    Top Padding
     * @param right  Right Padding
     * @param bottom Bottom Padding
     * @return {@code true} success, {@code false} fail
     */
    public static boolean setPadding(
            final Component[] views,
            final int left,
            final int top,
            final int right,
            final int bottom
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                setPadding(views[i], left, top, right, bottom);
            }
            return true;
        }
        return false;
    }

    // ==================
    // = RelativeLayout =
    // ==================

    /**
     * 设置 RelativeLayout Component 布局规则
     *
     * @param view {@link Component}
     * @param verb 布局位置
     * @return {@link Component}
     */
    public static Component addRule(
            final Component view,
            final int verb
    ) {
        return addRule(view, verb, -1);
    }

    /**
     * 设置 RelativeLayout Component 布局规则
     *
     * @param view    {@link Component}
     * @param verb    布局位置
     * @param subject 关联 Component id
     * @return {@link Component}
     */
    public static Component addRule(
            final Component view,
            final int verb,
            final int subject
    ) {
        if (view != null) {
            try {
                DependentLayout.LayoutConfig layoutParams = (DependentLayout.LayoutConfig) view.getLayoutConfig();
                layoutParams.addRule(verb, subject);
                view.setLayoutConfig(layoutParams);
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "addRule");
            }
        }
        return view;
    }

    /**
     * 移除 RelativeLayout Component 布局规则
     *
     * @param view {@link Component}
     * @param verb 布局位置
     * @return {@link Component}
     */
    public static Component removeRule(
            final Component view,
            final int verb
    ) {
        if (view != null) {
            try {
                DependentLayout.LayoutConfig layoutParams = (DependentLayout.LayoutConfig) view.getLayoutConfig();
                layoutParams.removeRule(verb);
                view.setLayoutConfig(layoutParams);
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "removeRule");
            }
        }
        return view;
    }

    /**
     * 获取 RelativeLayout Component 指定布局位置 Component id
     *
     * @param view {@link Component}
     * @param verb 布局位置
     * @return 关联 Component id
     */
    public static int getRule(
            final Component view,
            final int verb
    ) {
        if (view != null) {
            try {
                DependentLayout.LayoutConfig layoutParams = (DependentLayout.LayoutConfig) view.getLayoutConfig();
                return layoutParams.getRule(verb);
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "getRule");
            }
        }
        return 0;
    }

    // =

    /**
     * 设置多个 RelativeLayout Component 布局规则
     *
     * @param verb  布局位置
     * @param views Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean addRules(
            final int verb,
            final Component... views
    ) {
        return addRules(verb, -1, views);
    }

    /**
     * 设置多个 RelativeLayout Component 布局规则
     *
     * @param verb    布局位置
     * @param subject 关联 Component id
     * @param views   Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean addRules(
            final int verb,
            final int subject,
            final Component... views
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                addRule(views[i], verb, subject);
            }
            return true;
        }
        return false;
    }

    /**
     * 移除多个 RelativeLayout Component 布局规则
     *
     * @param verb  布局位置
     * @param views Component[]
     * @return {@code true} success, {@code false} fail
     */
    public static boolean removeRules(
            final int verb,
            final Component... views
    ) {
        if (views != null) {
            for (int i = 0, len = views.length; i < len; i++) {
                removeRule(views[i], verb);
            }
            return true;
        }
        return false;
    }

    // =============
    // = Animation =
    // =============

//    /**
//     * 设置动画
//     * @param view      {@link Component}
//     * @param animation {@link Animation}
//     * @return {@link Component}
//     */
//    public static Component setAnimation(
//            final Component view,
//            final Animation animation
//    ) {
//        return AnimationUtils.setAnimation(view, animation);
//    }
//
//    /**
//     * 获取动画
//     * @param view {@link Component}
//     * @return {@link Animation}
//     */
//    public static Animation getAnimation(final Component view) {
//        return AnimationUtils.getAnimation(view);
//    }
//
//    /**
//     * 清空动画
//     * @param view {@link Component}
//     * @return {@link Component}
//     */
//    public static Component clearAnimation(final Component view) {
//        return AnimationUtils.clearAnimation(view);
//    }
//
//    /**
//     * 启动动画
//     * @param view      {@link Component}
//     * @param animation {@link Animation}
//     * @return {@link Component}
//     */
//    public static Component startAnimation(
//            final Component view,
//            final Animation animation
//    ) {
//        return AnimationUtils.startAnimation(view, animation);
//    }
//
//    /**
//     * 启动动画
//     * @param animation {@link Animation}
//     * @param <T>       泛型
//     * @return {@link Animation}
//     */
//    public static <T extends Animation> T startAnimation(final T animation) {
//        return AnimationUtils.startAnimation(animation);
//    }
//
//    /**
//     * 取消动画
//     * @param view {@link Component}
//     * @return {@link Animation}
//     */
//    public static Animation cancelAnimation(final Component view) {
//        return AnimationUtils.cancelAnimation(view);
//    }
//
//    /**
//     * 取消动画
//     * @param animation {@link Animation}
//     * @param <T>       泛型
//     * @return {@link Animation}
//     */
//    public static <T extends Animation> T cancelAnimation(final T animation) {
//        return AnimationUtils.cancelAnimation(animation);
//    }

    // ========
    // = 背景 =
    // ========
    /**
     * 设置背景图片
     * @param view       {@link Component}
     * @param background 背景图片
     * @return {@link Component}
     */
    public static Component setBackground(
            final Component view,
            final Element background
    ) {
        if (view != null) {
            try {
                view.setBackground(background);
            } catch (Exception e) {
            }
        }
        return view;
    }
    /**
     * 设置背景图片
     *
     * @param view       {@link Component}
     * @param background 背景图片
     * @return {@link Component}
     */
    public static Component setBackground(
            final Component view,
            final String background
    ) {
        if (view != null) {
            try {
                ImageSource imageSourceNoOptions = ImageSource.create(background, null);
                PixelMap pixelMapNoOptions = imageSourceNoOptions.createPixelmap(null);
                PixelMapElement element = new PixelMapElement(pixelMapNoOptions);
                view.setBackground(element);
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "setBackground");
            }
        }
        return view;
    }

//    /**
//     * 设置背景颜色
//     * @param view  {@link Component}
//     * @param color 背景颜色
//     * @return {@link Component}
//     */
//    public static Component setBackgroundColor(
//            final Component view,
//            @ColorInt final int color
//    ) {
//        if (view != null) {
//            try {
//                view.setBackgroundColor(color);
//            } catch (Exception e) {
//                LogPrintUtils.eTag(TAG, e, "setBackgroundColor");
//            }
//        }
//        return view;
//    }

//    /**
//     * 设置背景资源
//     * @param view  {@link Component}
//     * @param resId resource identifier
//     * @return {@link Component}
//     */
//    public static Component setBackgroundResource(
//            final Component view,
//            @DrawableRes final int resId
//    ) {
//        if (view != null) {
//            try {
//                view.setBackgroundResource(resId);
//            } catch (Exception e) {
//                LogPrintUtils.eTag(TAG, e, "setBackgroundResource");
//            }
//        }
//        return view;
//    }

//    /**
//     * 设置背景着色颜色
//     * @param view {@link Component}
//     * @param tint 着色颜色
//     * @return {@link Component}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
//    public static Component setBackgroundTintList(
//            final Component view,
//            final ColorStateList tint
//    ) {
//        if (view != null) {
//            try {
//                view.setBackgroundTintList(tint);
//            } catch (Exception e) {
//                LogPrintUtils.eTag(TAG, e, "setBackgroundTintList");
//            }
//        }
//        return view;
//    }

//    /**
//     * 设置背景着色模式
//     * @param view     {@link Component}
//     * @param tintMode 着色模式 {@link PorterDuff.Mode}
//     * @return {@link Component}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
//    public static Component setBackgroundTintMode(
//            final Component view,
//            final PorterDuff.Mode tintMode
//    ) {
//        if (view != null) {
//            try {
//                view.setBackgroundTintMode(tintMode);
//            } catch (Exception e) {
//                LogPrintUtils.eTag(TAG, e, "setBackgroundTintMode");
//            }
//        }
//        return view;
//    }

    // ========
    // = 前景 =
    // ========

//    /**
//     * 设置前景图片
//     * @param view       {@link Component}
//     * @param foreground 前景图片
//     * @return {@link Component}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.M)
//    public static Component setForeground(
//            final Component view,
//            final Drawable foreground
//    ) {
//        if (view != null) {
//            try {
//                view.setForeground(foreground);
//            } catch (Exception e) {
//                LogPrintUtils.eTag(TAG, e, "setForeground");
//            }
//        }
//        return view;
//    }

    /**
     * 设置前景重心
     *
     * @param view    {@link Component}
     * @param gravity 重心
     * @return {@link Component}
     */
    public static Component setForegroundGravity(
            final Component view,
            final int gravity
    ) {
        if (view != null) {
            try {
                view.setForegroundGravity(gravity);
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "setForegroundGravity");
            }
        }
        return view;
    }
    /**
     * 设置背景颜色
     *
     * @param view  {@link Component}
     * @param color 背景颜色
     * @return {@link Component}
     */
    public static Component setBackgroundColor(
            final Component view,
            final int color
    ) {
        if (view != null) {
            try {
                ShapeElement shapeElement = new ShapeElement();
                shapeElement.setRgbColor(RgbColor.fromArgbInt(ResourceUtils.getColorForInt(color)));
                view.setBackground(shapeElement);
            } catch (Exception e) {
                LogUtils.error(TAG, e + "setBackgroundColor");
            }
        }
        return view;
    }
//    /**
//     * 设置前景着色颜色
//     * @param view {@link Component}
//     * @param tint 着色颜色
//     * @return {@link Component}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.M)
//    public static Component setForegroundTintList(
//            final Component view,
//            final ColorStateList tint
//    ) {
//        if (view != null) {
//            try {
//                view.setForegroundTintList(tint);
//            } catch (Exception e) {
//                LogPrintUtils.eTag(TAG, e, "setForegroundTintList");
//            }
//        }
//        return view;
//    }

//    /**
//     * 设置前景着色模式
//     * @param view     {@link Component}
//     * @param tintMode 着色模式 {@link PorterDuff.Mode}
//     * @return {@link Component}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.M)
//    public static Component setForegroundTintMode(
//            final Component view,
//            final PorterDuff.Mode tintMode
//    ) {
//        if (view != null) {
//            try {
//                view.setForegroundTintMode(tintMode);
//            } catch (Exception e) {
//                LogPrintUtils.eTag(TAG, e, "setForegroundTintMode");
//            }
//        }
//        return view;
//    }

    // ========
    // = 获取 =
    // ========

//    /**
//     * 获取 Component 背景 Drawable
//     * @param view {@link Component}
//     * @return 背景 Drawable
//     */
//    public static Drawable getBackground(final Component view) {
//        if (view != null) return view.getBackground();
//        return null;
//    }

//    /**
//     * 获取 Component 背景着色颜色
//     * @param view {@link Component}
//     * @return 背景着色颜色 {@link ColorStateList}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
//    public static ColorStateList getBackgroundTintList(final Component view) {
//        if (view != null) return view.getBackgroundTintList();
//        return null;
//    }
//
//    /**
//     * 获取 Component 背景着色模式
//     * @param view {@link Component}
//     * @return 背景着色模式 {@link PorterDuff.Mode}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
//    public static PorterDuff.Mode getBackgroundTintMode(final Component view) {
//        if (view != null) return view.getBackgroundTintMode();
//        return null;
//    }
//
//    // =
//
//    /**
//     * 获取 Component 前景 Drawable
//     * @param view {@link Component}
//     * @return 前景 Drawable
//     */
//    @RequiresApi(api = Build.VERSION_CODES.M)
//    public static Drawable getForeground(final Component view) {
//        if (view != null) return view.getForeground();
//        return null;
//    }
//
//    /**
//     * 获取 Component 前景重心
//     * @param view {@link Component}
//     * @return 前景重心 {@link Gravity}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.M)
//    public static int getForegroundGravity(final Component view) {
//        if (view != null) return view.getForegroundGravity();
//        return Gravity.FILL;
//    }
//
//    /**
//     * 获取 Component 前景着色颜色
//     * @param view {@link Component}
//     * @return 前景着色颜色 {@link ColorStateList}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.M)
//    public static ColorStateList getForegroundTintList(final Component view) {
//        if (view != null) return view.getForegroundTintList();
//        return null;
//    }
//
//    /**
//     * 获取 Component 前景着色模式
//     * @param view {@link Component}
//     * @return 前景着色模式 {@link PorterDuff.Mode}
//     */
//    @RequiresApi(api = Build.VERSION_CODES.M)
//    public static PorterDuff.Mode getForegroundTintMode(final Component view) {
//        if (view != null) return view.getForegroundTintMode();
//        return null;
//    }

    // ===========
    // = 着色处理 =
    // ===========

//    /**
//     * Component 着色处理
//     * @param view  {@link Component}
//     * @param color 颜色值
//     * @return {@link Component}
//     */
//    public static Component setColorFilter(
//            final Component view,
//             final int color
//    ) {
//        return setColorFilter(view, getBackground(view), color);
//    }

//    /**
//     * Component 着色处理, 并且设置 Background Drawable
//     * @param view     {@link Component}
//     * @param drawable {@link Drawable}
//     * @param color    颜色值
//     * @return {@link Component}
//     */
//    public static Component setColorFilter(
//            final Component view,
//            final Drawable drawable,
//            @ColorInt final int color
//    ) {
//        try {
//            setBackground(view, ImageUtils.setColorFilter(drawable, color));
//        } catch (Exception e) {
//            LogPrintUtils.eTag(TAG, e, "setColorFilter");
//        }
//        return view;
//    }

    // =

//    /**
//     * Component 着色处理
//     * @param view        {@link Component}
//     * @param colorFilter 颜色过滤 ( 效果 )
//     * @return {@link Component}
//     */
//    public static Component setColorFilter(
//            final Component view,
//            final ColorFilter colorFilter
//    ) {
//        return setColorFilter(view, getBackground(view), colorFilter);
//    }

//    /**
//     * Component 着色处理, 并且设置 Background Drawable
//     * @param view        {@link Component}
//     * @param drawable    {@link Drawable}
//     * @param colorFilter 颜色过滤 ( 效果 )
//     * @return {@link Component}
//     */
//    public static Component setColorFilter(
//            final Component view,
//            final Drawable drawable,
//            final ColorFilter colorFilter
//    ) {
//        try {
//            setBackground(view, ImageUtils.setColorFilter(drawable, colorFilter));
//        } catch (Exception e) {
//            LogPrintUtils.eTag(TAG, e, "setColorFilter");
//        }
//        return view;
//    }
}